package com.battery.system.service.battery.impl;

import java.util.List;

import com.battery.system.domain.BO.PartnerBO;
import com.battery.system.domain.Partner;
import com.battery.system.mapper.PartnerMapper;
import com.battery.system.service.impl.BaseServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.battery.system.mapper.PartnerInstallMapper;
import com.battery.system.domain.PartnerInstall;
import com.battery.system.service.battery.IPartnerInstallService;
import com.battery.common.core.text.Convert;

/**
 * 合作商设置Service业务层处理
 *
 * @author battery
 * @date 2021-01-21
 */
@Service
public class PartnerInstallServiceImpl extends BaseServiceImpl<PartnerInstall> implements IPartnerInstallService {
    @Autowired
    private PartnerInstallMapper partnerInstallMapper;


    @Autowired
    private PartnerMapper partnerMapper;

    /**
     * 查询合作商设置
     *
     * @param partnerId 合作商设置ID
     * @return 合作商设置
     */
    @Override
    public PartnerInstall selectPartnerInstallById(String partnerId) {
        return partnerInstallMapper.selectPartnerInstallById(partnerId);
    }

    /**
     * 查询合作商设置列表
     *
     * @param partnerInstall 合作商设置
     * @return 合作商设置
     */
    @Override
    public List<PartnerInstall> selectPartnerInstallList(PartnerInstall partnerInstall) {
        return partnerInstallMapper.selectPartnerInstallList(partnerInstall);
    }

    /**
     * 新增合作商设置
     *
     * @param partnerInstall 合作商设置
     * @return 结果
     */
    @Override
    public int insertPartnerInstall(PartnerInstall partnerInstall) {
        return partnerInstallMapper.insertPartnerInstall(partnerInstall);
    }

    /**
     * 修改合作商设置
     *
     * @param partnerInstall 合作商设置
     * @return 结果
     */
    @Override
    public int updatePartnerInstall(PartnerInstall partnerInstall) {
        return partnerInstallMapper.updatePartnerInstall(partnerInstall);
    }

    /**
     * 删除合作商设置对象
     *
     * @param ids 需要删除的数据ID
     * @return 结果
     */
    @Override
    public int deletePartnerInstallByIds(String ids) {
        return partnerInstallMapper.deletePartnerInstallByIds(Convert.toStrArray(ids));
    }

    /**
     * 删除合作商设置信息
     *
     * @param partnerId 合作商设置ID
     * @return 结果
     */
    @Override
    public int deletePartnerInstallById(String partnerId) {
        return partnerInstallMapper.deletePartnerInstallById(partnerId);
    }

    /**
     * 合作商设置
     *
     * @param partnerBO
     * @return
     */
    @Override
    public int setUpPartner(PartnerBO partnerBO) {

        PartnerInstall partnerInstallUpdate = new PartnerInstall();
        partnerInstallUpdate.setPartnerId(partnerBO.getPartnerId());
        partnerInstallUpdate.setTxBrokerage(partnerBO.getTxBrokerage());
        partnerInstallUpdate.setTxMinPermit(partnerBO.getTxMinPermit());
        partnerInstallUpdate.setOrderFreeMinute(partnerBO.getOrderFreeMinute());
        partnerInstallUpdate.setDailyOrderLimit(partnerBO.getDailyOrderLimit());
        partnerInstallUpdate.setmBl(partnerBO.getmBl());
        partnerInstallMapper.updateByPrimaryKeySelective(partnerInstallUpdate);


        Partner partnerUpdate = new Partner();
        partnerUpdate.setId(partnerBO.getPartnerId());
        partnerUpdate.setIcePoint(partnerBO.getIcePoint());
        partnerUpdate.setFrozenMoney(partnerBO.getFrozenMoney());
        partnerMapper.updateByPrimaryKeySelective(partnerUpdate);

        return 1;
    }
}
